<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Map</title>
</head>
<body>
    <script>
        // 定义
        let laoda = new Map([
            ["name", "老大"],
            ["gender", "男"],
            ["web", "https://www.laoda.com"]
        ]);
        console.log("laoda: ", laoda);
        
        // set 添加新元素
        laoda.set("height", 170);
        console.log("laoda: ", laoda);

        // get 获取元素
        console.log("get element, name: ", laoda.get("name"));

        // delete 删除元素
        laoda.delete("web");
        console.log("laoda: ", laoda);

        // has
        console.log("has height: ", laoda.has("height"));
        console.log("has web: ", laoda.has("web"));

        // size
        console.log("map size: ", laoda.size);

        // to array
        console.log("to array: ", Array.from(laoda));
        console.log("to array: ", [...laoda]);

        // to set ??
        console.log("to set: ", new Set(laoda));

        // for...of，元素为数组
        for (let item of laoda) {
            console.log("for...of: ", item);
        }

        for (let [k, v] of laoda) {
            console.log("for...of key: ", k, ", value: ", v);
        }

        // forEach
        laoda.forEach((v, k) => {
            console.log("forEach key: ", k, ", value: ", v);
        });

        // clear
        laoda.clear();
        console.log("clear: ", laoda);
    </script>
</body>
</html>